home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / cxhand.c < prev    next >
C/C++ Source or Header  |  1993-08-08  |  4KB  |  166 lines

  1. /*
  2.  *    Copyright (c) 1993 Michael D. Bayne.
  3.  *    All rights reserved.
  4.  *
  5.  *    Please see the documentation accompanying the distribution for distribution and disclaimer information.
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <dos/dos.h>
  10. #include <libraries/commodities.h>
  11. #include <devices/inputevent.h>
  12.  
  13. #include <clib/exec_protos.h>
  14. #include <clib/utility_protos.h>
  15. #include <clib/commodities_protos.h>
  16. #include <clib/alib_protos.h>
  17.  
  18. #include "defs.h"
  19. #include "Blanker_rev.h"
  20.  
  21. #include "protos/main.h"
  22. #include "protos/messaging.h"
  23.  
  24. #ifdef DICE
  25. __interrupt __geta4 VOID CxBFunc( CxMsg *, CxObj * );
  26. #endif
  27. #ifdef SASC
  28. VOID __interrupt __saveds CxBFunc( CxMsg *, CxObj * );
  29. #endif
  30.  
  31. struct    MsgPort        *bPort;
  32. CxObj            *bBroker, *pHotKey, *bHotKey, *objectList;
  33. ULONG            cxSigFlag, cxBlankFlag, timeCount = 0;
  34. struct    NewBroker    nbBroker = { NB_VERSION, "Blanker", VERS, "A system friendly screen blanker",
  35.             NBU_UNIQUE|NBU_NOTIFY, COF_SHOW_HIDE, 0, 0, 0 };
  36.  
  37. #ifdef DICE
  38. __interrupt VOID CxBFunc( CxMsg *CxMessage, CxObj *CxObject )
  39. #endif
  40. #ifdef SASC
  41. VOID __interrupt __saveds CxBFunc( CxMsg *CxMessage, CxObj *CxObject )
  42. #endif
  43. {
  44.     struct InputEvent *Event = ( struct InputEvent * )CxMsgData( CxMessage );
  45.  
  46.     if( Event->ie_Class == IECLASS_TIMER ) {
  47.         if( ++timeCount >= bPrefs->bp_Timeout ) {
  48.             Signal( Task, cxBlankFlag );
  49.             timeCount = 0;
  50.         }
  51.     } else if(( Event->ie_Class != IECLASS_RAWKEY )||(!( Event->ie_Code & IECODE_UP_PREFIX ))) {
  52.         if( bTask ) {
  53.             Signal( bTask, SIGBREAKF_CTRL_C );
  54.             bTask = 0L;
  55.         }
  56.         timeCount = 0;
  57.     }
  58. }
  59.  
  60. LONG handleCxMess( VOID )
  61. {
  62.     ULONG msgid, msgtype;
  63.     CxMsg *msg;
  64.  
  65.     while( msg = ( CxMsg * )GetMsg( bPort )) {
  66.         msgid = CxMsgID( msg );
  67.         msgtype = CxMsgType( msg );
  68.         ReplyMsg(( struct Message * )msg );
  69.  
  70.         switch( msgtype ) {
  71.         case CXM_IEVENT:
  72.             switch( msgid ) {
  73.             case EVT_CX_POPUP:
  74.                 openMainWindow();
  75.                 break;
  76.             case EVT_CX_BLANK:
  77.                 Signal( Task, cxBlankFlag );
  78.                 break;
  79.             }
  80.             break;
  81.         case CXM_COMMAND:
  82.         switch( msgid ) {
  83.             case CXCMD_DISABLE:
  84.                 ActivateCxObj( bBroker, 0l );
  85.                 break;
  86.             case CXCMD_ENABLE:
  87.                 ActivateCxObj( bBroker, 1l );
  88.                 break;
  89.             case CXCMD_KILL:
  90.                 return( QUIT );
  91.                 break;
  92.             case CXCMD_APPEAR:
  93.             case CXCMD_UNIQUE:
  94.                 openMainWindow();
  95.                 break;
  96.             case CXCMD_DISAPPEAR:
  97.                 closeMainWindow();
  98.                 break;
  99.             default:
  100.                 break;
  101.             }
  102.         default:
  103.             break;
  104.         }
  105.     }
  106.     return( OK );
  107. }
  108.  
  109. VOID ShutdownCX( VOID )
  110. {
  111.     CxMsg *msg;
  112.  
  113.     if( bPort ) {
  114.         if( bBroker ) DeleteCxObjAll( bBroker );
  115.         bBroker = 0l;
  116.         while( msg = ( CxMsg * )GetMsg( bPort )) ReplyMsg(( struct Message * )msg );
  117.         DeletePort( bPort );
  118.         bPort = 0l;
  119.     }
  120. }
  121.  
  122. LONG UpdateCX( VOID )
  123. {
  124.     ActivateCxObj( bBroker, 0l );
  125.  
  126.     DeleteCxObj( objectList );
  127.     DeleteCxObj( pHotKey );
  128.     DeleteCxObj( bHotKey );
  129.  
  130.     if( objectList = CxCustom( CxBFunc, 0L )) AttachCxObj( bBroker, objectList );
  131.     if( pHotKey = HotKey( bPrefs->bp_PopKey, bPort, EVT_CX_POPUP )) AttachCxObj( bBroker, pHotKey );
  132.     if( bHotKey = HotKey( bPrefs->bp_BlankKey, bPort, EVT_CX_BLANK )) AttachCxObj( bBroker, bHotKey );
  133.  
  134.     if(!( CxObjError( bBroker ))) ActivateCxObj( bBroker, 1l );
  135.     else {
  136.         ShutdownCX();
  137.         return( QUIT );
  138.     }
  139.     return( OK );
  140. }
  141.  
  142. LONG SetupCX( VOID )
  143. {
  144.     LONG cxError;
  145.  
  146.     if( bPort = CreatePort( 0L, 0 )) {
  147.         nbBroker.nb_Pri = bPrefs->bp_Priority;
  148.         nbBroker.nb_Port = bPort;
  149.         cxSigFlag = 1L << bPort->mp_SigBit;
  150.         bBroker = CxBroker( &nbBroker, &cxError );
  151.         if( cxError == CBERR_OK ) return( UpdateCX());
  152.         else ShutdownCX();
  153.     }
  154.     return( QUIT );
  155. }
  156.  
  157. LONG CheckCX( VOID )
  158. {
  159.     LONG cxError;
  160.  
  161.     bBroker = CxBroker( &nbBroker, &cxError );
  162.     DeleteCxObj( bBroker );
  163.     if( cxError == CBERR_OK ) return( OK );
  164.     return( QUIT );
  165. }
  166.